/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Gael
 */
@Entity
@NamedQueries({
    @NamedQuery(name="Magasin.findAll", query="select m from Magasin m"),
    @NamedQuery(name="Magasin.findById", query="select m from Magasin m where m.id = :magasinid"),
    @NamedQuery(name="Magasin.findByVendeur", query="select m from Magasin m where m.id = :Vendeur"),
    @NamedQuery(name="Magasin.findByName", query="select m from Magasin m where m.nom LIKE :mot"),
    @NamedQuery(name="Magasin.findByVille", query="select m from Magasin m where m.ville = :mot")
})
@XmlRootElement
public class Magasin implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String nom;
    private String description;
    private String adresse;
    private String ville;
    private int codepostal;
     @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
    private List<Produit> produits = new ArrayList();

    public Magasin(String nom, String description, String adresse, String ville, int codepostal) {
        this.nom = nom;
        this.description = description;
        this.adresse = adresse;
        this.ville = ville;
        this.codepostal = codepostal;
    }

    public Magasin() {
    }
     
    

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getAdresse() {
        return adresse;
    }

    public void setAdresse(String adresse) {
        this.adresse = adresse;
    }

    public String getVille() {
        return ville;
    }

    public void setVille(String ville) {
        this.ville = ville;
    }

    public int getCodepostal() {
        return codepostal;
    }

    public void setCodepostal(int codepostal) {
        this.codepostal = codepostal;
    }

    public List<Produit> getProduits() {
        return produits;
    }

    public void setProduits(List<Produit> produits) {
        this.produits = produits;
    }
    public void addProduit(Produit p) {
        this.produits.add(p);
    }

     
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Magasin)) {
            return false;
        }
        Magasin other = (Magasin) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Magasin[ id=" + id + " ]";
    }
    
}
